package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.mybatis.service.impl.CrudServiceImpl;
import com.example.dao.MdlUserDao;
import com.example.dto.MdlUserDTO;
import com.example.entity.MdlUserEntity;
import com.example.service.MdlUserService;
import com.example.utils.ConvertUtils;
import org.springframework.stereotype.Service;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

/**
 * 用户表
 *
 * @author yyyyjinying 1020066395@qq.com
 * @since 1.0-SNAPSHOT 2025-06-15
 */
@Service
public class MdlUserServiceImpl extends CrudServiceImpl<MdlUserDao, MdlUserEntity, MdlUserDTO> implements MdlUserService {

    @Override
    public QueryWrapper<MdlUserEntity> getWrapper(Map<String, Object> params){
        QueryWrapper<MdlUserEntity> wrapper = new QueryWrapper<>();

        String username = (String)params.get("username");
        wrapper.eq(StringUtils.isNotBlank(username), "username", username);
        String dharmaName = (String)params.get("dharmaName");
        wrapper.eq(StringUtils.isNotBlank(dharmaName), "dharma_name", dharmaName);

        return wrapper;
    }

    @Override
    public void save(MdlUserDTO dto) {
        MdlUserEntity entity = ConvertUtils.sourceToTarget(dto, MdlUserEntity.class);
        entity.setId(snowflake.nextId()); // 主键id可能有错误
        baseDao.insert(entity);
    }


}